<?php
// Error Reporting
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

// Version
define('ENGINE_NAME', 'Zoqa');
define('VERSION', '0.2');

// Define separators
defined('DS')
    || define('DS', '/');//DIRECTORY_SEPARATOR
defined('PS')
    || define('PS', PATH_SEPARATOR);

//
defined('REMOTE_SITE_DIR')
    || define('REMOTE_SITE_DIR', "remontik.kh.ua");

//
defined('PROTOCOL_TYPE')
    || define('PROTOCOL_TYPE', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'));

defined('PUBLIC_URL')
    || define('PUBLIC_URL', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http') . "://" . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != 80 ? ":{$_SERVER['SERVER_PORT']}" : '') . rtrim(dirname($_SERVER['SCRIPT_NAME']), DS));

defined('CURRENT_URL')
    || define('CURRENT_URL', PROTOCOL_TYPE . "://" . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != 80 ? ":{$_SERVER['SERVER_PORT']}" : '') . rtrim(dirname($_SERVER['SCRIPT_NAME']), DS));

//TODO
defined('IMAGES_WS_PATH')
    || define('IMAGES_WS_PATH', /*PUBLIC_URL .*/ '/public/images/' );

define ('FTP_HOST', '91.197.129.190');
define ('FTP_USER', 'babagayr');
define ('FTP_PASS', 'LJet118w3g');
define ('FTP_FRONTEND', 'remontik.kh.ua');
define ('FTP_BACKEND', 'admin');

define ('HTTP_FRONTEND', 'http://remontik.kh.ua');

define ('SESSION_SPACE', 'remontik');



// -- FireBug
require_once(PUBLIC_PATH . '/FirePHP/FirePHP.class.php');
require_once(PUBLIC_PATH . '/FirePHP/fb.php');

//
define('SMARTY_DIR', PUBLIC_PATH . '/Engine/Smarty/');
require_once(SMARTY_DIR . 'SmartyBC.class.php');
require_once(PUBLIC_PATH . '/Engine/Controller/abstract.Interface.php');
require_once(PUBLIC_PATH . '/Engine/Controller/BD.php');


// ----------------- обработчик ошибок ----------------- 
    function error_handler($errno, $errstr, $errfile, $errline) { 
      global $log, $config;
      
      $error_msg = '';
      
      switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
          $error = 'Notice';
          break;
        case E_WARNING:
        case E_USER_WARNING:
          $error = 'Warning';
          break;
        case E_ERROR:
        case E_USER_ERROR:
          $error = 'Fatal Error';
          break;
        default:
          $error = 'Unknown';
          break;
      }
        
     // if ($config->get('config_error_display'))  
        $error_msg = '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>';
            
      // if ($config->get('config_error_log'))  
      //  $log->write('PHP ' . $error . ':  ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
      
      if($error_msg != '') fb("Startup.php: " . $error_msg);
     
      return true;
    }
      
// Error Handler
set_error_handler('error_handler',E_STRICT);

// Check Version
if (version_compare(phpversion(), '5.1.0', '<') == true) {
	exit('PHP5.1+ Required');
}

// Register Globals
if (ini_get('register_globals')) {
	ini_set('session.use_cookies', 'On');
	ini_set('session.use_trans_sid', 'Off');
		
	session_set_cookie_params(0, '/');
	session_start();
	
	$globals = array($_REQUEST, $_SESSION, $_SERVER, $_FILES);

	foreach ($globals as $global) {
		foreach(array_keys($global) as $key) {
			unset(${$key}); 
		}
	}
}

// Magic Quotes Fix
if (ini_get('magic_quotes_gpc')) {
	function clean($data) {
   		if (is_array($data)) {
  			foreach ($data as $key => $value) {
    			$data[clean($key)] = clean($value);
  			}
		} else {
  			$data = stripslashes($data);
		}
	
		return $data;
	}			
	
	$_GET = clean($_GET);
	$_POST = clean($_POST);
	$_REQUEST = clean($_REQUEST);
	$_COOKIE = clean($_COOKIE);
}

if (!ini_get('date.timezone')) {
	date_default_timezone_set('UTC');
}

// Windows IIS Compatibility  
if (!isset($_SERVER['DOCUMENT_ROOT'])) { 
	if (isset($_SERVER['SCRIPT_FILENAME'])) {
		$_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
	}
}
 
if (!isset($_SERVER['DOCUMENT_ROOT'])) {
	if (isset($_SERVER['PATH_TRANSLATED'])) {
		$_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])));
	}
}

if (!isset($_SERVER['REQUEST_URI'])) { 
	$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1); 
	
	if (isset($_SERVER['QUERY_STRING'])) { 
		$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];  
	} 
}
 
// Движок
require_once(PUBLIC_PATH . '/config/#db.conn.php');
require_once(PUBLIC_PATH . '/Engine/Controller/Controller.php');
require_once(PUBLIC_PATH . '/Engine/View/View.php');
require_once(PUBLIC_PATH . '/Engine/Model/Model.php');
require_once(PUBLIC_PATH . '/Engine/Controller/BD.php');
require_once(PUBLIC_PATH . '/Engine/registry.php');
require_once(PUBLIC_PATH . '/Engine/loader.php');
require_once(PUBLIC_PATH . '/Engine/config.php');
require_once(PUBLIC_PATH . '/Engine/log.php');
require_once(PUBLIC_PATH . '/Engine/request.php');
require_once(PUBLIC_PATH . '/Engine/session.php');
require_once(PUBLIC_PATH . '/Engine/widget.php');


// Библиотеки
require_once(PUBLIC_PATH . '/Engine/lib/class.User.php');


// Debug
require(PUBLIC_PATH . '/debug.php');

// jqGrid
//require(PUBLIC_PATH . '/Engine/jqGrid.php');
//require(PUBLIC_PATH . '/Engine/jqGridPdo.php');
//require(PUBLIC_PATH . '/Engine/jqUtils.php');

// Zend
require_once PUBLIC_PATH . '/Zend/Loader/ClassMapAutoloader.php';
$loader = new Zend\Loader\ClassMapAutoloader();
$loader->registerAutoloadMap(PUBLIC_PATH . '/Zend/autoload_classmap.php');
$loader->register();


/*
// Helper
require_once(DIR_SYSTEM . 'helper/json.php'); 
require_once(DIR_SYSTEM . 'helper/utf8.php'); 

// Engine
require_once(DIR_SYSTEM . 'engine/action.php'); 
require_once(DIR_SYSTEM . 'engine/controller.php');
require_once(DIR_SYSTEM . 'engine/front.php');
require_once(DIR_SYSTEM . 'engine/loader.php'); 
require_once(DIR_SYSTEM . 'engine/model.php');


// Common
require_once(DIR_SYSTEM . 'library/cache.php');
require_once(DIR_SYSTEM . 'library/url.php');
require_once(DIR_SYSTEM . 'library/config.php');
require_once(DIR_SYSTEM . 'library/db.php');
require_once(DIR_SYSTEM . 'library/document.php');
require_once(DIR_SYSTEM . 'library/image.php');
require_once(DIR_SYSTEM . 'library/language.php');
require_once(DIR_SYSTEM . 'library/log.php');
require_once(DIR_SYSTEM . 'library/mail.php');
require_once(DIR_SYSTEM . 'library/pagination.php');
require_once(DIR_SYSTEM . 'library/response.php');
require_once(DIR_SYSTEM . 'library/session.php');
require_once(DIR_SYSTEM . 'library/template.php');
*/
?>